package data.join.com.service;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;

/**
 * Created by Administrator on 2016/6/3.
 */
public abstract class BaseService extends Service {

    private static final int START_DELAY = 20*1000;
    protected Handler mHandler = new Handler();

    protected abstract void startWork();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        long upTime = SystemClock.uptimeMillis();

        int startDelay = 100;

        if(upTime < 6*60*1000){
            startDelay = START_DELAY;
        }

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startWork();
            }
        },startDelay);
    }

    @Override
    public int onStartCommand(Intent intent,int flags, int startId) {
        return START_STICKY;
    }

}
